/**
 * json格式字符串转成日期；
 * 如new Date(parseInt(1358784000000)).toLocaleString() 结果为：2013年1月22日 0:00:00
 * @param cellval
 * @returns
 */
function jsonDateFormat(time) {
    var datetime = new Date();
    datetime.setTime(time);
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
    var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
    var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    var rd = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
    //alert(rd.indexOf('.'));
    //rd = rd.substring(0,rd.indexOf('.'));
    //alert(time);
    return rd;
}

//处理oracle返回null的值为空，避免在页面上显示 null；
function doNull(s) {
    if (s == null) {
        return '';
    } else {
        return s;
    }
}

//处理oracle返回null的值为空，避免在页面上显示 null；
function doSubstring(s) {
    if (s == null) {
        return '';
    } else {
        if (s.length > 20) {
            //alert(s);
            s = s.substring(0, 20) + "......";
        }
        return s;
    }
}

//去掉字符串'.'后面字符，如去掉日期型后面多出来的'.0'；
function doZero(s) {
    if (s == null) {
        return '';
    } else {
        //alert(s.indexOf('.'));
        var ret = "";
        if (s.indexOf('.') > 0) {
            ret = s.substring(0, s.indexOf('.'));
        }
        //alert(ret);
        return ret;
    }
}

//放大缩小
function showOrHidden() {
    $("#cxDiv").toggle();
    $("#fsDiv").toggleClass("glyphicon glyphicon-resize-full glyphicon glyphicon-resize-small");
}

/**
 * 主要依托于jquery,使用一个div对数据进行增删改查操作通用函数进行封装抽象
 * @auth dave
 * @date 2016-2-8
 */

//显示新增界面
function showAddDiv(name, basePath) {
    /*重置表单*/
    $("#ffAdd")[0].reset();

    //设置addHeaderDiv标题文字及按钮
    setHeader("新增" + name, basePath);

    //设置adddiv的 操作按钮
    setButtonDivAdd();

    //显示adddiv
    $("#add").modal("show");
}

//显示新增界面
function showAddDiv2(name, basePath) {
    /*重置表单*/
    $("#ffAdd")[0].reset();

    //设置addHeaderDiv标题文字及按钮
    setHeader2("新增" + name, basePath);

    //设置adddiv的 操作按钮
    setButtonDivAdd();

    //显示adddiv
    $("#add").modal("show");
}

//显示修改界面--查询单条数据，url如：<%=basePath%>cust/getCust?id="+id
function myGetEdit(name, basePath) {
    /*重置表单*/
    //$("#ffAdd")[0].reset();

    //设置addHeaderDiv标题文字及按钮
    setHeader("修改" + name, basePath);

    //设置adddiv的 操作按钮
    setButtonDivEdit();

    //显示adddiv
    $("#add").modal("show");
}

//显示详情信息界面
function myGetView(name, basePath) {
    /*重置表单*/
    //$("#ffAdd")[0].reset();

    //设置addHeaderDiv标题文字及按钮
    setHeader("查看" + name, basePath);

    //设置adddiv的 操作按钮
    setButtonDivView();

    //显示adddiv
    $("#add").modal("show");
}

//设置addHeaderDiv标题文字及按钮
function setHeader(name, basePath) {
    var headerDiv = "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>";
    headerDiv += "<h5 class='modal-title'><img src='" + basePath + "' alt='' class='img-rounded'>&nbsp;" + name + "信息</h5>";
    $("#addHeaderDiv").html(headerDiv);

}

//设置addHeaderDiv标题文字及按钮
function setHeader2(name, basePath) {
    var headerDiv = "<h5 class='modal-title'>" + basePath + name + "信息</h5>";
    $("#addHeaderDiv").html(headerDiv);

}

//-------------------add、edit、view三种按钮设置-------start--------------------
//设置addDiv的 add操作按钮
function setButtonDivAdd() {
    var buttons = '<button type="submit" class="btn btn-sm btn-primary"  name="addSaveButton" id="addSaveButton">保存</button>';
    buttons += '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal">关闭</button>';
    buttons += '<input type="hidden" name="opType" id="opType" value="add">';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 add操作按钮
function setButtonDivAdd2() {
    var buttons = '<button type="submit" class="btn btn-sm btn-primary"  name="addSaveButton" id="addSaveButton">保存</button>';
    buttons += '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)" id="curdfh">返回</button>';
    buttons += '<input type="hidden" name="opType" id="opType" value="add">';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 add操作按钮
function setButtonDivAdd3() {
    var buttons = '<button type="submit" class="btn btn-sm btn-primary"  name="addSaveButton" id="addSaveButton">保存</button>';
    buttons += '&nbsp;&nbsp;<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)"  id="curdfh">返回</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    $("#buttonDivTB").html(buttons);
}

//设置addDiv的 edit操作按钮
function setButtonDivEdit() {
    var buttons = '<button type="submit" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">修改</button>';
    buttons += '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal">关闭</button>';
    buttons += '<input type="hidden" name="opType" id="opType" value="edit">';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 edit操作按钮
function setButtonDivEdit2() {
    var buttons = '<button type="submit" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">修改</button>';
    buttons += '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)"  id="curdfh">返回</button>';
    buttons += '<input type="hidden" name="opType" id="opType" value="edit">';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 edit操作按钮
function setButtonDivEdit4() {
    var buttons = '<button type="button" class="btn btn-sm btn-success" onclick="tjsh()" name="tjshSaveButton" id="tjshSaveButton">提交审核</button>';
    buttons += '<button type="submit" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">修改</button>';
    buttons += '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)"  id="curdfh">返回</button>';
    buttons += '<input type="hidden" name="opType" id="opType" value="edit">';
    $("#buttonDiv").html(buttons);
}

//设置上部addDiv的 edit操作按钮
function setButtonDivEdit3() {
    var buttons = '<button type="submit" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">修改</button>';
    buttons += '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)"  id="curdfh">返回</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    $("#buttonDivTB").html(buttons);
}

//设置addDiv的 view操作按钮
function setButtonDivView() {
    var buttons = '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal">关闭</button>';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 view操作按钮
function setButtonDivView2() {
    var buttons = '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)">返回</button>';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 view 提交审批操作按钮
function setButtonDivView2TJ() {
    var buttons = '<button type="button" class="btn btn-sm btn-primary" name="editSaveButton" id="editSaveButton">提交审核</button>';
    buttons += '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)"  id="curdfh">返回</button>';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 view操作按钮
function setButtonDivView3() {
    var buttons = '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="gbc()">返回</button>';
    $("#buttonDiv").html(buttons);
}

//设置addDiv的 view操作按钮
function setButtonDivView4() {
    var buttons = '<button type="button" class="btn btn-sm btn-danger" data-dismiss="modal" onclick="history.go(-1)"  id="curdfh">返回</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    $("#buttonDivTB").html(buttons);
}

//关闭层
function gbc() {
    //$("#add").modal("show");
    $("#add").toggle();
}

//-------------------add、edit、view三种按钮设置--------end-------------------

//新增
function myTab1Add(url) {
    //$("#add").modal("hide");
    var postData = $("#ffAdd").serializeArray();
    //var url = "<%=basePath%>cust/saveCust";
    $.post(url, postData, function (data) {
        //var data = $.parseJSON(data);
        if (data.result == "success") {
            //保存成功  1.关闭弹出层，
            showSuccessTips("恭喜保存成功!", "提示");
            //2.重置输入框值为空，
            return true;
        } else {
            showErrorTips("保存数据失败!", "错误信息：");
            return false;
        }
    }).error(function () {
        showErrorTips("保存数据失败!", "错误信息：");
        return false;
    });
}

//新增
function myAdd(url) {
    $("#add").modal("hide");
    var postData = $("#ffAdd").serializeArray();
    //var url = "<%=basePath%>cust/saveCust";
    $.post(url, postData, function (data) {
        //var data = $.parseJSON(data);
        if (data.result == "success") {
            //保存成功  1.关闭弹出层，
            showSuccessTips("恭喜保存成功!", "提示");
            //2.重置输入框值为空，
            //3.刷新表格数据
            Search(0);
        } else {
            showErrorTips("保存数据失败!", "错误信息：");
        }
    }).error(function () {
        showErrorTips("保存数据失败!", "错误信息：");
    });
}

//修改--url如："<%=basePath%>cust/updateCust"
function myEdit(url) {
    $("#add").modal("hide");
    var postData = $("#ffAdd").serializeArray();
    //url = "<%=basePath%>cust/updateCust";
    $.post(url, postData, function (data) {
        //var data = $.parseJSON(json);
        if (data.result == "success") {
            //保存成功  1.关闭弹出层，2.重置输入框值为空，3.刷新表格数据
            showSuccessTips("恭喜修改成功", "提示");
            Search(0);
        } else {
            //showErrorTips("修改数据失败!", "错误信息：");
            $("#myModal").modal('show'); //hide;
            $("#myModalMessDiv").val("修改数据失败!失败原因：" + data.info);
        }
    }).error(function () {
        //showErrorTips("修改数据失败!", "错误信息：");
        $("#myModal").modal('show'); //hide;
        $("#myModalMessDiv").val("修改数据失败!失败原因：" + data.info);
    });
}

function myEdit2(url) {
    var postData = $("#ffAdd").serializeArray();
    //alert("22222");
    $.post(url, postData, function (data) {
        //alert("00000000");
        if (data.result == "success") {
            showSuccessTips("恭喜修改成功", "提示");
        } else {
            //alert("111111111");
            $("#editSaveButton").removeAttr("disabled")
            $("#tjshSaveButton").removeAttr("disabled");
            //showErrorTips("修改数据失败!", "错误信息：");
            $("#myModal").modal('show'); //hide;
            $("#myModalMessDiv").html("<font color='red'>对不起修改数据失败，失败原因：" + data.info + "</font>");
        }
    }).error(function () {
        $("#editSaveButton").removeAttr("disabled");
        //showErrorTips("修改数据失败!", "错误信息：");
        $("#myModal").modal('show'); //hide;
        $("#myModalMessDiv").html("<font color='red'>对不起修改数据失败，失败原因：" + data.info + "</font>");
    });
}

//生效or失效-- url 如： "<%=basePath%>cust/delCust?id=" + id
function setNewsStatus(url) {
    $.get(url, function (data) {
        if ("success" == data.result) {
            showSuccessTips("设置成功", "提示");
            Search(0);
        } else {
            showErrorTips("设置数据" + id + "失败!", "错误信息：");
        }
    });
}

//生效or失效-- url 如： "<%=basePath%>cust/delCust?id=" + id
function myEffect(url) {
    $.get(url, function (data) {
        if ("success" == data.result) {
            showSuccessTips("生效/作废成功", "提示");
            Search(0);
        } else {
            showErrorTips("生效/作废数据" + id + "失败!", "错误信息：");
        }
    });
}

//删除-- url 如： "<%=basePath%>cust/delCust?id=" + id
function myDel(url) {
    $.get(url, function (data) {
        if ("success" == data.result) {
            showSuccessTips("删除成功", "提示");
            Search(0);
        } else {
            showErrorTips("删除数据" + id + "失败!", "错误信息：");
        }
    });
}

//提交审核-- url 如： "<%=basePath%>cust/tjsh?id=" + id
function myTjsh(url) {
    $.get(url, function (data) {
        if ("success" == data.result) {
            showSuccessTips("提交审核成功", "提示");
            Search(0);
        } else {
            showErrorTips("提交审核数据" + id + "失败!", "错误信息：");
        }
    });
}

//提交审核-- url 如： "<%=basePath%>cust/tjsh?id=" + id
function myCurdTjsh(url) {
    var postData = $("#ffAdd").serializeArray();
    $.post(url, postData, function (data) {
        //var data = $.parseJSON(json);
        if (data.result == "success") {
            showSuccessTips("恭喜," + data.info, "提示");
        } else {
            $("#editSaveButton").removeAttr("disabled");
            $("#tjshSaveButton").removeAttr("disabled");
            //showErrorTips("提交审核失败!原因："+data.info, "错误信息：");
            $("#myModal").modal('show'); //hide;
            $("#myModalMessDiv").html("<font color='red'>对不起,提交审核失败，失败原因：" + data.info + "</font>");
        }
    }).error(function () {
        $("#editSaveButton").removeAttr("disabled");
        $("#tjshSaveButton").removeAttr("disabled");
        //showErrorTips("提交审核失败!原因："+data.info, "错误信息：");
        $("#myModal").modal('show'); //hide;
        $("#myModalMessDiv").html("<font color='red'>对不起,提交审核失败，失败原因：" + data.info + "</font>");
    });
}

//审核页面：通过： 提交审核通过弹出框，并且根据选择confirm结果调用具体提交函数；
function confirmMyCurdShtg(url) {
    bootbox.confirm({
        size: 'small',
        buttons: {
            confirm: {
                label: '  确认   ',
                className: 'btn btn-sm btn-danger'
            },
            cancel: {
                label: '  取消    ',
                className: 'btn btn-success btn-sm'
            }
        },
        message: '您确认要审核通过？',
        callback: function (result) {
            if (result) {
                if (result) {
                    myCurdShtg(url);
                }
            }
        },
        title: '确认提示：',
        className: ' '
    })
}

//审核页面：退回： 提交审核通过弹出框，并且根据选择confirm结果调用具体提交退回函数；
function confirmMyCurdShth(url) {
    bootbox.confirm({
        size: 'small',
        buttons: {
            confirm: {
                label: ' 退回 ',
                className: 'btn btn-sm btn-danger'
            },
            cancel: {
                label: '   取消     ',
                className: 'btn btn-success btn-sm'
            }
        },
        message: '您确认要退回？',
        callback: function (result) {
            if (result) {
                if (result) {
                    myCurdShth(url);
                }
            }
        },
        title: '确认提示：',
        className: ' '
    })
}

//审核通过-- url 如： "<%=basePath%>cust/tjsh?id=" + id
function myCurdShtg(url) {
    var note = $("#note").val();
	if ( null == note||note=="" ) {
        alert("审核意见不能为空！");
        $("#note").focus();
    } else {
        var postData = $("#shUpdate").serializeArray();
        //url = "<%=basePath%>cust/updateCust";
        $.post(url, postData, function (data) {
            //var data = $.parseJSON(json);
            if (data.result == "success") {
                showSuccessTips("恭喜," + data.info, "提示");
                $("#shtgButton").attr("disabled", true);
                $("#shthButton").attr("disabled", true);
                $("#shthzfqrButton").attr("disabled", true);
            } else {
                //showErrorTips("提交审核通过失败!原因："+data.info, "错误信息：");
                $("#myModal").modal('show'); //hide;
                $("#myModalMessDiv").html("<font color='red'>对不起,提交审核通过失败，失败原因：" + data.info + "</font>");
            }
        }).error(function () {
            $("#shtgButton").attr("disabled", true);
            $("#shthButton").attr("disabled", true);
            $("#shthzfqrButton").attr("disabled", true);
            //showErrorTips("提交审核通过失败!原因："+data.info, "错误信息：");
            $("#myModal").modal('show'); //hide;
            $("#myModalMessDiv").html("<font color='red'>对不起,提交审核通过失败，失败原因：" + data.info + "</font>");
        });
    }
}

//审核退回-- url 如： "<%=basePath%>cust/tjsh?id=" + id
function myCurdShth(url) {
    var note = $("#note").val();
	if ( null == note||note=="" ) {
        alert("审核意见不能为空！");
        $("#note").focus();
    } else {
        var postData = $("#shUpdate").serializeArray();
        //url = "<%=basePath%>cust/updateCust";
        $.post(url, postData, function (data) {
            //var data = $.parseJSON(json);
            if (data.result == "success") {
                $("#shtgButton").attr("disabled", true);
                $("#shthButton").attr("disabled", true);
                $("#shthzfqrButton").attr("disabled", true);
                showSuccessTips("恭喜，" + data.info, "提示");
            } else {
                //showErrorTips("提交审核退回失败!原因："+data.info, "错误信息：");
                $("#myModal").modal('show'); //hide;
                $("#myModalMessDiv").html("<font color='red'>对不起,提交审核退回失败，失败原因：" + data.info + "</font>");
            }
        }).error(function () {
            $("#shtgButton").attr("disabled", true);
            $("#shthButton").attr("disabled", true);
            $("#shthzfqrButton").attr("disabled", true);
            //showErrorTips("提交审核退回失败!原因："+data.info, "错误信息：");
            $("#myModal").modal('show'); //hide;
            $("#myModalMessDiv").html("<font color='red'>对不起,提交审核退回失败，失败原因：" + data.info + "</font>");
        });
    }
}


//*------------------------全选反选 start-----------------------------------

//全选和反选
function selectAll() {
    var checklist = document.getElementsByName("batchSelected"); //所有复选框id名字
    if (document.getElementById("batchSelectedAll").checked) { //全选按钮所在check的名称
        for (var i = 0; i < checklist.length; i++) {
            checklist[i].checked = 1;
        }
    } else {
        for (var j = 0; j < checklist.length; j++) {
            checklist[j].checked = 0;
        }
    }
}

//得到多选框选中的单个值
function getCheckboxValue() {
    var checkbox = checkfunctionIDS();
    if (checkbox != false) {
        return checkbox.value;
    }
}

//得到多选框选中的单个值
function getCheckboxMutlValue() {
    var checkbox = checkfunctionMutlIDS();
    if (checkbox != false) {
        return checkbox.value;
    }
}

//校验多选框,选中多条记录，并返回该记录的id；适用于选择多条记录操作。
function checkfunctionMutlIDS() {
    var obj, count, obj1, checkvalue;
    checkvalue = "";
    obj = document.getElementsByName("batchSelected");
    count = 0;
    //alert("obj.length="+obj.length);
    for (i = 0; i < obj.length; i++) {
        //alert("33333");
        if (obj[i].checked == true) {
            count++;
            checkvalue += obj[i].value + ";";
            //var cid =$(obj[i]).val();
            //alert("选中数据="+checkvalue);
        }
    }
    if (count < 1) {
        alert("请至少选择一条资源进行操作！");
        //showWarnTips("请至少选择一条资源进行操作！!", "提示信息：");
        return false;
    }
    alert("checkvalue=" + checkvalue);
    return checkvalue;
}

//校验多选框,如果是只选中一条记录，并返回该记录的id；适用于选择一条记录进行查看、修改、删除操作。
function checkfunctionIDS() {
    //alert("checkfunctionIDS start");
    //alert("prop="+$("#batchSelected").prop("checked"));

    var obj, count, obj1, checkvalue;
    checkvalue = "";
    obj = document.getElementsByName("batchSelected");
    //alert(obj);
    count = 0;
    //alert("obj.length="+obj.length);
    for (i = 0; i < obj.length; i++) {
        //alert("3333");
        if (obj[i].checked == true) {
            //alert("44444");
            count++;
            //obj1 =obj[i];
            checkvalue = obj[i].value;
            //var cid =$(obj[i]).val();
            //alert("value="+$(obj[i]).attr("value")+";checkvalue="+cid+";obj[i].value=="+obj[i].value);
        }
    }
    //alert("55555");
    if (count < 1) {
        //alert("请至少选择一条资源进行操作！");
        showWarnTips("请至少选择一条资源进行操作！!", "提示信息：");
        return false;
    } else if (count > 1) {
        //alert("最多只能选择一条记录进行操作，您选择了"+count+"条记录！");
        showWarnTips("最多只能选择一条记录进行操作，您选择了" + count + "条记录！", "提示信息：");
        return false;
    }
    //return obj1.value;
    //alert("checkvalue="+checkvalue);
    return checkvalue;
}

//全选函数
function quanxuan(idsname) {
    //alert("idsname="+idsname+"");
    //eval(alert("eval print="+""+idsname));
    for (i = 0; i < idsname.length; i++) {
        //alert(idsname[i].value);
        idsname[i].checked = true;
        //alert("checked="+idsname[i].checked);
    }
}

//反选函数
function fanxuan(idsname) {
    for (i = 0; i < idsname.length; i++) {
        idsname[i].checked = false;
        //alert("checked="+idsname[i].checked);
    }
}

//*---------------------全选反选结束---------------------------------------------------


//错误信息提示
function showErrorTips(errorMes, errorTitle) {
    toastr.error(errorMes, errorTitle)
    toastr.options = {
        "closeButton": true,
        "debug": false,
        "positionClass": "toast-bottom-full-width",
        "showDuration": "300",
        "hideDuration": "1000",
        "timeOut": "30000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    }
}

//成功信息提示框
function showSuccessTips(successMes, successTitle) {
    toastr.success(successMes, successTitle)
    toastr.options = {
        "closeButton": true,
        "debug": false,
        "positionClass": "toast-bottom-full-width",
        "showDuration": "300",
        "hideDuration": "1000",
        "timeOut": "5000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    }
}

//警告信息提示
function showWarnTips(warnMes, warnTitle) {
    toastr.warning(warnMes, warnTitle)
    toastr.options = {
        "closeButton": true,
        "debug": false,
        "positionClass": "toast-bottom-full-width",
        "showDuration": "300",
        "hideDuration": "1000",
        "timeOut": "5000",
        "extendedTimeOut": "1000",
        "showEasing": "swing",
        "hideEasing": "linear",
        "showMethod": "fadeIn",
        "hideMethod": "fadeOut"
    }
}

//自动装载jquery form edit数据到 form表单中元素
function loadData(jsonStr) {
    //var obj = eval("("+jsonStr+")");
    var obj = jsonStr; //形如：  Object {startNo: 0, endNo: 0, pageSize: 0, pkName: null, pkValue: null…}
    var key, value, tagName, type, arr;
    for (x in obj) {
        key = x;
        value = obj[x];

        $("[name='" + key + "'],[name='" + key + "[]']").each(function () {
            tagName = $(this)[0].tagName;
            type = $(this).attr('type');
            if (tagName == 'INPUT') {
                if (type == 'radio') {
                    $(this).attr('checked', $(this).val() == value);
                } else if (type == 'checkbox') {
                    arr = value.split(',');
                    for (var i = 0; i < arr.length; i++) {
                        if ($(this).val() == arr[i]) {
                            $(this).attr('checked', true);
                            break;
                        }
                    }
                } else {
                    $(this).val(value);
                }
            } else if (tagName == 'SELECT' || tagName == 'TEXTAREA') {
                $(this).val(value);
            }

        });
    }
}

/**
 * @param {} obj
 * 将ajax访问后得到的对象进行遍历 再使用jquery其职放入到同属性名的dom元素中
 */
function setValue(obj) {
    // 开始遍历
    for (var p in obj) {
        // 方法
        if (typeof (obj[p]) == "function") {
            // obj[p]();
        } else {
            $("#" + p).val(obj[p]);
            // p 为属性名称，obj[p]为对应属性的值，会造成select的值跟着变化。
        }
    }
}

//jqueryvalidate 使用的配置
/*
jQuery.extend(jQuery.validator.messages, {
	required: "必选字段",
	remote: "请修正该字段",
	email: "请输入正确格式的电子邮件",
	url: "请输入合法的网址",
	date: "请输入合法的日期",
	dateISO: "请输入合法的日期 (ISO).",
	number: "请输入合法的数字",
	digits: "只能输入整数",
	creditcard: "请输入合法的信用卡号",
	equalTo: "请再次输入相同的值",
	accept: "请输入拥有合法后缀名的字符串",
	maxlength: jQuery.validator.format("请输入一个长度最多是 {0} 的字符串"),
	minlength: jQuery.validator.format("请输入一个长度最少是 {0} 的字符串"),
	rangelength: jQuery.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
	range: jQuery.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
	max: jQuery.validator.format("请输入一个最大为 {0} 的值"),
	min: jQuery.validator.format("请输入一个最小为 {0} 的值")
});
*/
/*****************************************************************
 jQuery Validate扩展验证方法  (davexin)
 *****************************************************************/
/*
$(function(){
// 判断整数value是否等于0
jQuery.validator.addMethod("isIntEqZero", function(value, element) {
value=parseInt(value);
return this.optional(element) || value==0;
}, "整数必须为0");

// 判断整数value是否大于0
jQuery.validator.addMethod("isIntGtZero", function(value, element) {
value=parseInt(value);
return this.optional(element) || value>0;
}, "整数必须大于0");

// 判断整数value是否大于或等于0
jQuery.validator.addMethod("isIntGteZero", function(value, element) {
value=parseInt(value);
return this.optional(element) || value>=0;
}, "整数必须大于或等于0");

// 判断整数value是否不等于0
jQuery.validator.addMethod("isIntNEqZero", function(value, element) {
value=parseInt(value);
return this.optional(element) || value!=0;
}, "整数必须不等于0");

// 判断整数value是否小于0
jQuery.validator.addMethod("isIntLtZero", function(value, element) {
value=parseInt(value);
return this.optional(element) || value<0;
}, "整数必须小于0");

// 判断整数value是否小于或等于0
jQuery.validator.addMethod("isIntLteZero", function(value, element) {
value=parseInt(value);
return this.optional(element) || value<=0;
}, "整数必须小于或等于0");

// 判断浮点数value是否等于0
jQuery.validator.addMethod("isFloatEqZero", function(value, element) {
value=parseFloat(value);
return this.optional(element) || value==0;
}, "浮点数必须为0");

// 判断浮点数value是否大于0
jQuery.validator.addMethod("isFloatGtZero", function(value, element) {
value=parseFloat(value);
return this.optional(element) || value>0;
}, "浮点数必须大于0");

// 判断浮点数value是否大于或等于0
jQuery.validator.addMethod("isFloatGteZero", function(value, element) {
value=parseFloat(value);
return this.optional(element) || value>=0;
}, "浮点数必须大于或等于0");

// 判断浮点数value是否不等于0
jQuery.validator.addMethod("isFloatNEqZero", function(value, element) {
value=parseFloat(value);
return this.optional(element) || value!=0;
}, "浮点数必须不等于0");

// 判断浮点数value是否小于0
jQuery.validator.addMethod("isFloatLtZero", function(value, element) {
value=parseFloat(value);
return this.optional(element) || value<0;
}, "浮点数必须小于0");

// 判断浮点数value是否小于或等于0
jQuery.validator.addMethod("isFloatLteZero", function(value, element) {
value=parseFloat(value);
return this.optional(element) || value<=0;
}, "浮点数必须小于或等于0");

// 判断浮点型
jQuery.validator.addMethod("isFloat", function(value, element) {
return this.optional(element) || /^[-\+]?\d+(\.\d+)?$/.test(value);
}, "只能包含数字、小数点等字符");

// 匹配integer
jQuery.validator.addMethod("isInteger", function(value, element) {
return this.optional(element) || (/^[-\+]?\d+$/.test(value) && parseInt(value)>=0);
}, "匹配integer");

// 判断数值类型，包括整数和浮点数
jQuery.validator.addMethod("isNumber", function(value, element) {
return this.optional(element) || /^[-\+]?\d+$/.test(value) || /^[-\+]?\d+(\.\d+)?$/.test(value);
}, "匹配数值类型，包括整数和浮点数");

// 只能输入[0-9]数字
jQuery.validator.addMethod("isDigits", function(value, element) {
return this.optional(element) || /^\d+$/.test(value);
}, "只能输入0-9数字");

// 判断中文字符
jQuery.validator.addMethod("isChinese", function(value, element) {
return this.optional(element) || /^[\u0391-\uFFE5]+$/.test(value);
}, "只能包含中文字符。");

// 判断英文字符
jQuery.validator.addMethod("isEnglish", function(value, element) {
return this.optional(element) || /^[A-Za-z]+$/.test(value);
}, "只能包含英文字符。");

// 手机号码验证
jQuery.validator.addMethod("isMobile", function(value, element) {
var length = value.length;
return this.optional(element) || (length == 11 && /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value));
}, "请正确填写您的手机号码。");

// 电话号码验证
jQuery.validator.addMethod("isPhone", function(value, element) {
var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
return this.optional(element) || (tel.test(value));
}, "请正确填写您的电话号码。");

// 联系电话(手机/电话皆可)验证
jQuery.validator.addMethod("isTel", function(value,element) {
var length = value.length;
var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
return this.optional(element) || tel.test(value) || (length==11 && mobile.test(value));
}, "请正确填写您的联系方式");

// 匹配qq
jQuery.validator.addMethod("isQq", function(value, element) {
return this.optional(element) || /^[1-9]\d{4,12}$/;
}, "匹配QQ");

// 邮政编码验证
jQuery.validator.addMethod("isZipCode", function(value, element) {
var zip = /^[0-9]{6}$/;
return this.optional(element) || (zip.test(value));
}, "请正确填写您的邮政编码。");

// 匹配密码，以字母开头，长度在6-12之间，只能包含字符、数字和下划线。
jQuery.validator.addMethod("isPwd", function(value, element) {
return this.optional(element) || /^[a-zA-Z]\\w{6,12}$/.test(value);
}, "以字母开头，长度在6-12之间，只能包含字符、数字和下划线。");

// 身份证号码验证
jQuery.validator.addMethod("isIdCardNo", function(value, element) {
//var idCard = /^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\w)$/;
return this.optional(element) || isIdCardNo(value);
}, "请输入正确的身份证号码。");

// IP地址验证
jQuery.validator.addMethod("ip", function(value, element) {
return this.optional(element) || /^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.)(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.){2}([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))$/.test(value);
}, "请填写正确的IP地址。");

// 字符验证，只能包含中文、英文、数字、下划线等字符。
jQuery.validator.addMethod("stringCheck", function(value, element) {
return this.optional(element) || /^[a-zA-Z0-9\u4e00-\u9fa5-_]+$/.test(value);
}, "只能包含中文、英文、数字、下划线等字符");

// 匹配english
jQuery.validator.addMethod("isEnglish", function(value, element) {
return this.optional(element) || /^[A-Za-z]+$/.test(value);
}, "匹配english");

// 匹配汉字
jQuery.validator.addMethod("isChinese", function(value, element) {
return this.optional(element) || /^[\u4e00-\u9fa5]+$/.test(value);
}, "匹配汉字");

// 匹配中文(包括汉字和字符)
jQuery.validator.addMethod("isChineseChar", function(value, element) {
return this.optional(element) || /^[\u0391-\uFFE5]+$/.test(value);
}, "匹配中文(包括汉字和字符) ");

// 判断是否为合法字符(a-zA-Z0-9-_)
jQuery.validator.addMethod("isRightfulString", function(value, element) {
return this.optional(element) || /^[A-Za-z0-9_-]+$/.test(value);
}, "判断是否为合法字符(a-zA-Z0-9-_)");

// 判断是否包含中英文特殊字符，除英文"-_"字符外
jQuery.validator.addMethod("isContainsSpecialChar", function(value, element) {
var reg = RegExp(/[(\ )(\`)(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\+)(\=)(\|)(\{)(\})(\')(\:)(\;)(\')(',)(\[)(\])(\.)(\<)(\>)(\/)(\?)(\~)(\！)(\@)(\#)(\￥)(\%)(\…)(\&)(\*)(\（)(\）)(\—)(\+)(\|)(\{)(\})(\【)(\】)(\‘)(\；)(\：)(\”)(\“)(\’)(\。)(\，)(\、)(\？)]+/);
return this.optional(element) || !reg.test(value);
}, "含有中英文特殊字符");


//身份证号码的验证规则
function isIdCardNo(num){
//if (isNaN(num)) {alert("输入的不是数字！"); return false;}
var len = num.length, re;
if (len == 15)
re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{2})(\w)$/);
else if (len == 18)
re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\w)$/);
else {
//alert("输入的数字位数不对。");
return false;
}
var a = num.match(re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
else
{
var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
if (!B) {
//alert("输入的身份证号 "+ a[0] +" 里出生日期不对。");
return false;
}
}
if(!re.test(num)){
//alert("身份证最后一位只能是数字和字母。");
return false;
}
return true;
}

});

//车牌号校验
function isPlateNo(plateNo){
var re = /^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$/;
if(re.test(plateNo)){
return true;
}
return false;
}

*/

//**********************************表单操作开始****************************
/**
 * 功能 ：将表单的所有input都设为只读
 *@param 要操作表单的i
 */
function formReadOnly(formId) {
    $("#" + formId + " input,textarea").attr("readOnly", true);
    $("#" + formId + " input,textarea").css('backgroundColor', '#ececec');
}

/**
 * 功能 ：将表单的所有input都设为只读
 *@param 要操作表单的i
 */
function formReadOnly2(formId) {
    $("#" + formId + " input").attr("readOnly", true);
    $("#" + formId + " input").css('backgroundColor', '#ececec');
}

/**
 * 功能 ：将给定的input设为只读
 * @param array 数组，存放有要操作的input的id
 */
function inputReadOnly(array) {
    for (var i = 0; i < array.length; i++) {
        $('#' + array[i]).attr("readOnly", true);
        $('#' + array[i]).css('backgroundColor', '#ececec');
    }
}

/**
 * 功能 ：将表单的所有input都设为可编辑的
 *@param 要操作表单的id
 */
function formWritable(formId) {
    $("#" + formId + " input,textarea").removeAttr("readonly");
    $("#" + formId + " input,textarea").css('backgroundColor', '#FFF');
}

/**
 * 功能 ：将给定的input设为可编辑
 * @param array 数组，存放有要操作的input的id
 */
function inputWriteable(array) {
    for (var i = 0; i < array.length; i++) {
        $('#' + array[i]).removeAttr("readonly");
        $('#' + array[i]).css('backgroundColor', '#FFF');
    }
}

//*****************************表单操作结束**************************************

// 数字格式化千分位,
// 通过id获取对应输入值；
function number_formatInit(hiddenid, id) {
    var num = $("#"+hiddenid).val();  //document.getElementById(id);
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
            num.substring(num.length-(4*i+3));
    var retval = (((sign)?'':'-') + num + '.' + cents);
    //alert(retval);

    //首先设置后台数字类型字段值，不能用格式化带逗号的格式字符串，因为后台是数值型值；
    $("#"+hiddenid).val(rmoney(retval));

    //设置格式化显示字段值
    $("#"+id).val(retval);
}

//数字格式化千分位,
// 通过id获取对应输入值；
function number_format(id, hiddenid) {
    var num = $("#"+id).val();  //document.getElementById(id);
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
            num.substring(num.length-(4*i+3));
    var retval = (((sign)?'':'-') + num + '.' + cents);
    //alert(retval);

    //首先设置后台数字类型字段值，不能用格式化带逗号的格式字符串，因为后台是数值型值；
    $("#"+hiddenid).val(rmoney(retval));

    //设置格式化显示字段值
    $("#"+id).val(retval);
}

//取消格式化方法
function rmoney(e) {
    return parseFloat(e.replace(/[^\d\.-]/g, ""));
}

//--------------------初始化时间,id为要初始化对象的id，typeid为初始化何种格式的：1:-年月日时分秒格式；2：年月日格式------------------------------------
function initTime(id, typeid) {
    var now = new Date();
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var day = now.getDate();
    var hh = now.getHours();
    var mm = now.getMinutes();
    var ss = now.getSeconds();
    //var days  = getDaysInMonth(year, month);
    if (month < 10) {
        month = '0' + month;
    }
    if (day < 10) {
        day = '0' + day;
        //alert("day < 9="+ (day < 9) );
    }
    //modify by davexin @2021-11-7 start
    if (hh < 10) {
        hh = '0' + hh;
    }
    if (mm < 10) {
        mm = '0' + mm;
    }
    if (ss < 10) {
        ss = '0' + ss;
    }
    //modify by davexin @2021-11-7  end

    //var start = $("#start_time").val();
    //var end   = $("#end_time").val();
    var ctime = "";
    //alert("typeid="+typeid);
    if (typeid == "1") {
        ctime = year + '-' + month + '-' + day + " " + hh + ":" + mm + ":" + ss;
    } else if (typeid == "2") {
        ctime = year + '-' + month + '-' + day;
    } else {
        //ctime = year+'-'+month+'-01';
    }

    //alert("当前时间="+ctime);

    //if(start == '' & end == ''){
    $("#" + id).attr('value', ctime);
    //$("#end_time").attr('value', year+'-'+month+'-'+days);
    //}
}

//根据年月获取当月天数
function getDaysInMonth(year, month) {
    month = parseInt(month, 10);
    var temp = new Date(year, month, 0);
    return temp.getDate();
}

//-------------------初始化时间end-------------------------------------

//删除附件列表中第i个附件
function delfile(filegroupno, newfilename, id) {
    //先删除全部的附件；
    var urldel = "<%=basePath%>file/delUploadfileByGroupno?filegroup=" + filegroupno + "&time=" + Math.random();
    myDel(urldel);

    //再查询删除后附件列表展示；
    var url = "<%=basePath%>file/getAllUploadfile?startIndex=0&pageSize=1000&filegroup=" + filegroupno + "&time=" + Math.random();
    //alert(url);
    $("#fileListDiv").innerHTML = "";
    $("#ext1").html("");
    $("#ext2").html("");
    $.getJSON(url, function (data) {
        var ext1 = "";
        var ext2 = "";
        //1、表格行内容输出
        $.each(data.items, function (i, item) {
            var str = "<tr>";
            str += "<td><a href='<%=basePath%>download?filename=" + item.fileName + "'>" + item.ext1 + "</a><a href='#' onclick='delfile(" + filegroup + "," + item.fileName + ")' ><font color='red'>删除</font></a></td>";
            str += "</tr>";
            $("#fileListDiv").append(str);

            if ("" == ext1) {
                ext1 += item.fileName;
                ext2 += item.ext1;
            } else {
                ext1 += ";" + item.fileName;
                ext2 += ";" + item.ext1;
            }
        });//end each data;
        $("#ext1").val(ext1);
        $("#ext2").val(ext2);
    })//end getJSON;
}

//加载历史审核意见并显示
function SearchSHNotesList(urlSHYJList) {
    //alert(urlSHYJList);
    $.getJSON(urlSHYJList, function (data) {
        //$("#pageSize").html(data.pageSize);
        $("#totalCount").html(data.totalCount);
        $("#totalPageNo").html(data.totalPageNo);
        $("#grid_body").html("");
        //1、表格行内容输出
        $.each(data.items, function (i, item) {
            var str = "<tr>";
            str += "<td>" + doNull(item.tninstanceid) + "</td>";
            str += "<td>" + doNull(item.updatetime) + "</td>";
            str += "<td>" + doNull(item.updater) + "</td>";
            if (item.tninstancestatus == 0) {
                str += "<td><span class='label label-success'>审批中</span></td>";
            } else if (item.tninstancestatus == 1) {
                str += "<td><span class='label label-success'>通过</span></td>";
            } else if (item.tninstancestatus == 2) {
                str += "<td><span class='label label-danger'>已退回</span></td>";
            } else {
                str += "<td><span class='label label-danger'></span></td>";
            }
            str += "<td>" + doNull(item.laststep) + "</td>";
            str += "<td>" + doNull(item.note) + "</td>";
            str += "<td>" + doNull(item.firststep) + "</td>";
            str += "</tr>";
            $("#grid_body").append(str);
        });//end each data;
    })//end getJSON;
}

//加载流程相关信息并显示
function SearchProcessTaskNodes(urlTaskNode, urlSHYJList) {
    //alert(urlTaskNode);
    $.getJSON(urlTaskNode, function (data) {
        $("#totalCount").html(data.totalCount);
        $("#totalPageNo").html(data.totalPageNo);
        $("#grid_body").html("");
        var str = "<tr>";
        //1、表格行内容输出; 倒序输出，因为后台是倒序取得数据；
        $.each(data.items.reverse(), function (i, item) {
            str += "<td width='100px'>" + doNull(item.ext5) + "<br>" + doNull(item.nodename) + "<br>" + doNull(item.userid) + "</td>";
            if (i != data.items.length - 1) {
                str += "<td  width='50px' valign='middle' align='center'><br><img src='<%=basePath%>/images/jiantou3.jpg' width='30px' height='30px' ></td>"
            }
        });//end each data;
        str += "</tr>";
        $("#grid_process_body").append(str);
        //加载历史审核意见
        SearchSHNotesList(urlSHYJList);
    })//end getJSON;
}
